﻿Ext.define('App.views.AppSelectorGrid', {
    extend: 'Ext.grid.Panel',
    requires: [
            'Ext.data.StoreManager',
            'Ext.ModelManager',
            'Ext.data.Model',
            'Ext.util.Grouper',
            'App.desktop.Workspace'
        ],
    alias: 'widget.AppSelectorGrid',
    data: [],
    store: Ext.create('Ext.data.Store', {
        fields: [
            'Name',
            'Permissions'
            ],
        data: []
    }),
    columns: [
        {
            text: 'Name',
            dataIndex: 'Name',
            width: 250,
            sortable: false
        },
        {
            text: 'Permissions',
            dataIndex: 'Permissions',
            sortable: false
        }
    ],

    initComponent: function () {

        this.store.loadData(this.data);
        this.callParent();
    },

    selectApp: function () {

        sel = this.getSelectionModel().getSelection();

        if (sel.length == 0) {

            App.desktop.Workspace.showError('Which application do you want to access?', 'Please select an application');
            return false;
        }

        App.desktop.Workspace.selectApp(sel[0].data);
        return true;
    }
});